package com.punch.punchtable.controller;

import com.punch.punchtable.entity.LogLogin;
import com.punch.punchtable.service.LogLoginService;
import com.punch.punchtable.utils.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * @author 朱宗辉
 * @version V1.0
 * @Package com.punch.punchtable.controller
 * @date 2021/7/16 1:56
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private LogLoginService logLoginService;

    @PostMapping("/login")
    @ResponseBody
    public T login(@RequestBody LogLogin logLogin, HttpServletRequest request) {
        T t = new T();
        LogLogin logLogin1 = logLoginService.login(logLogin);
        if (logLogin1 != null) {
            t.add("user", logLogin1);
            t.setStatus(200);
            HttpSession session = request.getSession();
            session.setAttribute("login_username",logLogin1.getUsernum());
        } else {
            t.add("error","错误，用户名或密码有误");
            t.setStatus(500);
        }
        return t;
    }
}
